package com.usian.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.mapper.ShopMapper;
import com.usian.mapper.UserMapper;
import com.usian.pojo.shop.Shop;
import com.usian.pojo.user.User;
import com.usian.service.UserService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Resource
    private RedisTemplate<Object,Object> redisTemplate;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public Integer decideRidByUid(Integer uid) {
        return userMapper.decideRidByUid(uid);
    }

    @Override
    public List<Shop> listByStateLt3() {
        return shopMapper.listByStateLt3();
    }

    @Override
    public List<Shop> listByStateGt5() {
        //得到集合找出上架的商品
        List<Shop> shopList = shopMapper.listByStateGt5();
        //对于上架的商品存入redis，key为sku_xxxx(商品id) value 为商品对象   存String类型
        for (Shop shop : shopList) {
            if (shop.getState().equals(7)){
                redisTemplate.opsForValue().set(String.valueOf(shop.getSid()),shop.toString());
                System.out.println("Redis--------上架商品==========     "+shop);
            }
        }
        return shopList;
    }
}
